package com.ruoyi.production.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.production.domain.WorkReport;
import com.ruoyi.production.service.IWorkReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 报工记录Controller
 *
 * @author ruoyi
 * @date 2022-09-05
 */
@RestController
@RequestMapping("/production/WorkReport")
public class WorkReportController extends BaseController {
    @Autowired
    private IWorkReportService workReportService;

    /**
     * 查询报工记录列表
     */
    @PreAuthorize("@ss.hasPermi('production:WorkReport:list')")
    @GetMapping("/list")
    public TableDataInfo list(WorkReport workReport) {
        startPage();
        List<WorkReport> list = workReportService.selectWorkReportList(workReport);
        return getDataTable(list);
    }

    /**
     * 导出报工记录列表
     */
    @PreAuthorize("@ss.hasPermi('production:WorkReport:export')")
    @Log(title = "报工记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WorkReport workReport) {
        List<WorkReport> list = workReportService.selectWorkReportList(workReport);
        ExcelUtil<WorkReport> util = new ExcelUtil<WorkReport>(WorkReport.class);
        util.exportExcel(response, list, "报工记录数据");
    }

    /**
     * 获取报工记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('production:WorkReport:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(workReportService.selectWorkReportById(id));
    }

    /**
     * 新增报工记录
     */
    @PreAuthorize("@ss.hasPermi('production:WorkReport:add')")
    @Log(title = "报工记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WorkReport workReport) {
        return toAjax(workReportService.insertWorkReport(workReport));
    }

    /**
     * 修改报工记录
     */
    @PreAuthorize("@ss.hasPermi('production:WorkReport:edit')")
    @Log(title = "报工记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorkReport workReport) {
        return toAjax(workReportService.updateWorkReport(workReport));
    }

    /**
     * 删除报工记录
     */
    @PreAuthorize("@ss.hasPermi('production:WorkReport:remove')")
    @Log(title = "报工记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(workReportService.deleteWorkReportByIds(ids));
    }
}
